'*******************************************************************************
' *  
' *  Product: GSALib
' *  Description: A C# API for accessing the Google Search Appliance.
' *
' *  (c) Copyright 2008 Michael Cizmar + Associates Ltd.  (MC+A)
' *  
'*******************************************************************************


Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.IO
Imports System.Xml
Imports System.Collections

Namespace GSALib.GSA
    ''' <summary>
    ''' Class for building response supported in GSA
    ''' <para>Author Albert Ghukasyan</para>
    ''' </summary>
    Friend NotInheritable Class ResponseBuilder
#Region "Constructor"

        Private xmlParser As Utils.XMLParser = New GSALib.Utils.XMLParser()
        Friend Sub New()
        End Sub

#End Region

#Region "buildResponse Methode"

        ''' <summary>
        ''' Builds Response and saveing to file
        ''' </summary>
        ''' <param name="istream">Web Request returned Stream</param>
        ''' <param name="GSAHostAddress">Not Used Yet</param>
        ''' <param name="path">Path to file to where need to save data</param>
        ''' <returns></returns>
        Public Function buildResponse(ByVal istream As StreamReader, ByVal GSAHostAddress As String, ByVal path As String) As Response
            xmlParser.Parse(istream)
            If path IsNot Nothing Then
                Try
                    Dim sw As System.IO.StreamWriter = New StreamWriter(path)
                    sw.AutoFlush = True
                    sw.Write(xmlParser.sb.ToString())
                    sw.Close()
                Catch ex As Exception
                    Throw New Exceptions.GSAInvalidFileException("Invalide File Specified", ex.StackTrace)
                End Try
            End If
            Return xmlParser.getGSAResponse()
        End Function

#End Region
    End Class

End Namespace
